﻿@inject IPopupService PopupService



    <CnGalWebSite.Components.Buttons.MasaButton Text="添加发行版本" OnClick="OnClickInput" Icon="@IconType.Publisher.ToIconString()" Class="mb-4" />
    <MSimpleTable Class="mb-4">
        <thead>
            <tr>
                <th class="text-left">
                    类型
                </th>
                <th class="text-left">
                    名称
                </th>
                <th class="text-left">
                    发行平台
                </th>
                <th class="text-left">
                    游戏平台
                </th>
                <th class="text-left">
                    发行时间
                </th>
                <th class="text-left">
                    引擎
                </th>
                <th class="text-left">
                    平台Id/链接
                </th>
                <th class="text-left">
                    操作
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.OrderBy(s => s.Time))
            {
                <tr @key="@(item.PublishPlatformType.GetDisplayName()+item.PublishPlatformName+item.Link+item.Name)">
                    <td style="overflow-wrap: anywhere; ">@item.Type.GetDisplayName()</td>
                    <td style="overflow-wrap: anywhere; ">@item.Name</td>
                    <td style="overflow-wrap: anywhere; ">
                        @if (item.PublishPlatformType == PublishPlatformType.Other)
                        {
                            <span>@item.PublishPlatformName</span>
                        }
                        else
                        {
                            <span>@item.PublishPlatformType.GetDisplayName()</span>
                        }

                    </td>
                    <td style="overflow-wrap: anywhere; ">
                        @string.Join("、", item.GamePlatformTypes.Select(s=>s.GetDisplayName()))
                    </td>
                    <td style="overflow-wrap: anywhere; ">
                        @if (string.IsNullOrWhiteSpace(item.TimeNote))
                        {
                            if (item.Time != null)
                            {
                                <span>@item.Time.Value.ToString("yyyy年M月d日")</span>
                            }
                        }
                        else
                        {
                            <span>@item.TimeNote</span>
                            if (item.Time != null)
                            {
                                <span>@item.Time.Value.ToString("(yyyy年M月d日)")</span>
                            }
                        }
                    </td>
                    <td style="overflow-wrap: anywhere; ">@item.Engine</td>
                    <td style="overflow-wrap: anywhere; ">@item.Link</td>
                    <td>
                        <CnGalWebSite.Components.Buttons.MasaButton Tooltip="编辑" OnClick="@(()=>OnEdit(item))" Icon="@IconType.Edit.ToIconString()" Color="success" />
                        <CnGalWebSite.Components.Buttons.MasaButton Tooltip="删除" OnClick="@(()=>OnDelete(item))" Icon="@IconType.Delete.ToIconString()" Color="error" />
                    </td>
                </tr>
            }
        </tbody>
    </MSimpleTable>

    <InputCard @ref="inputCard" OnChanged="OnChanged" Items="Model" />


@code {
    [Parameter]
    public List<EditReleaseModel> Model { get; set; }

    InputCard inputCard;

    public void OnClickInput()
    {
        if (inputCard != null)
        {
            inputCard.Refresh(null);
        }
    }

    public void OnDelete(EditReleaseModel model)
    {
        Model.Remove(model);
    }

    public void OnEdit(EditReleaseModel model)
    {
        if (inputCard != null)
        {
            inputCard.Refresh(model);
        }
    }

    public void OnChanged()
    {
        Model.RemoveAll(s => string.IsNullOrWhiteSpace(s.Name));
        StateHasChanged();
    }
}
